﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Data;

namespace Dry.DbInterpreter
{
    public class DbTableInfo : General.DryBase
    {
        private string _strTableName;

        public string TableName
        {
            get { return _strTableName; }
            set { _strTableName = value; }
        }

        public string ObjectName
        {
            get { return TableName.Substring(3, 1).ToLower() + TableName.Substring(4); }
        }

        public string ClassName
        {
            get { return TableName.Substring(3); }
        }

        public static SqlDataReader GetDbTableInfo(string strTableName) 
        {
            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(GetSqlTableInfo(strTableName));
            
            return (SqlDataReader) db.ExecuteReader(dbCommand);
        }

        private static string GetSqlTableInfo(string strTableName)
        {
            return "SELECT EnumName, " + strTableName.Substring(3) + "Id AS Id" +
                    " FROM " + strTableName;
        }
    }
}
